import { tableColumns } from './data'
import { Button, Input, InputNumber, Select, Space } from 'ant-design-vue'
import { BusinessPageTypeEnum } from '@/enums/pageTypeEnum'
import { sheLfEnum } from '@/views/base/product/data'

export function useColumns(
  deleteRow: Function,
  setProductToTableData: Function,
  priceOrNumberChange: Function,
  payment: Function,
  productOptionData: any,
  businessType: any
) {
  // 开启产品行可筛选
  const filterOption = (input: string, option: any) => {
    return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0
  }

  const getColumns = (column, record, index) => {
    if (column.dataIndex === 'productName') {
      return (
        <Select
          showSearch
          disabled={businessType === BusinessPageTypeEnum.DETAIL || record.paymentStatus === 1}
          v-model={[record.productCode, 'value']}
          filterOption={filterOption}
          style={'width: 150px'}
          options={productOptionData}
          onChange={(value: string) => {
            setProductToTableData(value, index)
          }}
        ></Select>
      )
    } else if (column.dataIndex === 'productSpecification') {
      return <Input v-model={[record.productSpecification, 'value']} disabled style={'width: 150px'}></Input>
    } else if (column.dataIndex === 'productPacking') {
      return <Input v-model={[record.productPacking, 'value']} disabled style={'width: 150px'}></Input>
    } else if (column.dataIndex === 'productShelfLife') {
      return <Input v-model={[record.productShelfLife, 'value']} disabled style={'width: 150px'}></Input>
    } else if (column.dataIndex === 'productUniqueCode') {
      return <Input v-model={[record.productUniqueCode, 'value']} disabled style={'width: 150px'}></Input>
    } else if (column.key === 'productTotal') {
      return <Input value={record.purchasingPrice * record.purchaseNumber} disabled style={'width: 150px'}></Input>
    } else if (column.dataIndex === 'purchasingPrice') {
      return (
        <InputNumber
          min={0}
          v-model={[record.purchasingPrice, 'value']}
          onChange={priceOrNumberChange}
          disabled={businessType === BusinessPageTypeEnum.DETAIL || record.paymentStatus === 1}
          style={'width: 50px'}
        ></InputNumber>
      )
    } else if (column.dataIndex === 'purchaseNumber') {
      return (
        <InputNumber
          min={0}
          v-model={[record.purchaseNumber, 'value']}
          onChange={priceOrNumberChange}
          disabled={businessType === BusinessPageTypeEnum.DETAIL || record.paymentStatus === 1}
          style={'width: 50px'}
        ></InputNumber>
      )
    } else if (column.dataIndex === 'arrivalNumber') {
      return (
        <InputNumber
          min={0}
          max={record.purchaseNumber}
          v-model={[record.arrivalNumber, 'value']}
          disabled={businessType === BusinessPageTypeEnum.DETAIL}
          onChange={priceOrNumberChange}
          style={'width: 50px'}
        ></InputNumber>
      )
    } else if (column.dataIndex === 'remark') {
      return (
        <Input
          v-model={[record.remark, 'value']}
          disabled={businessType === BusinessPageTypeEnum.DETAIL}
          style={'width: 150px'}
        ></Input>
      )
    } else if (column.key === 'action') {
      return (
        <Space>
          <Button type='link' onClick={() => deleteRow(index)}>
            删除
          </Button>
          <Button
            disabled={businessType !== BusinessPageTypeEnum.UPDATE || record.paymentStatus === 1}
            type='link'
            onClick={() => payment(index)}
          >
            打款
          </Button>
        </Space>
      )
    }
  }
  return {
    getColumns,
    tableColumns
  }
}
